package cn.kinoko.service.common.util;

import cn.kinoko.common.constant.HeaderConstant;
import cn.kinoko.common.utils.SpringHelper;
import cn.kinoko.common.utils.ThreadLocalUtil;
import cn.kinoko.model.user.entity.UserInfo;
import cn.kinoko.service.common.CommonService;

/**
 * @author kinoko
 */
public class AuthUtil {

    private static final CommonService commonService = SpringHelper.getBean(CommonService.class);

    /**
     * 获取当前用户信息
     *
     * @return 用户信息
     */
    public static UserInfo getCurrentUser() {
        return commonService.currentUser();
    }

    /**
     * 获取当前用户id
     *
     * @return 用户id
     */
    public static Long getUid() {
        return (Long) ThreadLocalUtil.get(HeaderConstant.UID_HEADER);
    }

    /**
     * 获取当前用户id
     *
     * @return 用户id
     */
    public static Long getUidAndCheck() {
        return getCurrentUser().getUid();
    }

}
